package com.jdd.pedicure.service;

import com.jdd.pedicure.dao.OrderDao;
import com.jdd.pedicure.entity.Orders;
import com.jdd.pedicure.entity.Result;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class OrderService {
    @Resource
    OrderDao orderDao;

    public Orders queryById(int id) {
        return orderDao.getOne(id);
    }

    public List<Orders> queryAll() {
        return orderDao.findAll();
    }

    public void delete(int id) {
        orderDao.deleteById(id);
    }

    public void saveOrUpdate(Orders orders) {
        orderDao.save(orders);
    }

    public Result<Orders> queryByPage(Result<Orders> result) {
        PageRequest request = new PageRequest(result.getPage() - 1, result.getLimit());
        Example<Orders> ex = Example.of(result.getExample());
        Page<Orders> all = orderDao.findAll(ex, request);
        result.setData(all.getContent());
        result.setCount((int) all.getTotalElements());
        return result;
    }

    public String getbest() {
       return orderDao.getbest();
    }
}
